<?php

/**
 * Created by PhpStorm.
 * User: d7
 * Date: 2016/2/1
 * Time: 10:13
 */
class Image extends MY_Admin_Controller
{
    function __construct()
    {
        parent::__construct();
        $this->load->helper('image_helper');
        $this->config->load('image');
        $this->assign('index_channel','contents');
    }

    function add($type,$id){
        $image_type = $this->config->item('image_type');
        $this->assign('image_type',$image_type);
        $this->assign('type',$type);
        $this->assign('id',$id);
        $this->display();
    }

    function upload(){
        $type = $this->input->post('type');
        $id = $this->input->post('id');
        $settings = $this->config->item($type);
        $upload = $this->upload_image('Filedata', $settings, $id);
        if (!$upload) {
            $this->json_response(false, array(), '图片上传失败');
        }

        /*$this->load->model($settings['model_path']);
        $data = array(
            'id'    =>  $id,
            $settings['field'] => $upload['save_path'],
        );
        $model = $settings['model'];
        $this->$model->save($data);*/
        $this->json_response(true);
    }

}